package com.wz.project.bas.basProductDetail.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.basProductDetail.domain.BasProductDetail;
import com.wz.project.bas.basProductDetail.service.IBasProductDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物品明细Controller
 * 
 * @author wz
 * @date 2021-11-17
 */
@Controller
@RequestMapping("/bas/basProductDetail")
public class BasProductDetailController extends BaseController
{
    private String prefix = "bas/basProductDetail";

    @Autowired
    private IBasProductDetailService basProductDetailService;

//    @RequiresPermissions("bas:basProductDetail:view")
    @GetMapping()
    public String basProductDetail()
    {
        return prefix + "/basProductDetail";
    }

    /**
     * 查询物品明细列表
     */
//    @RequiresPermissions("bas:basProductDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasProductDetail basProductDetail)
    {
        startPage();
        List<BasProductDetail> list = basProductDetailService.selectBasProductDetailList(basProductDetail);
        return getDataTable(list);
    }

    /**
     * 导出物品明细列表
     */
//    @RequiresPermissions("bas:basProductDetail:export")
    @Log(title = "物品明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasProductDetail basProductDetail)
    {
        List<BasProductDetail> list = basProductDetailService.selectBasProductDetailList(basProductDetail);
        ExcelUtil<BasProductDetail> util = new ExcelUtil<BasProductDetail>(BasProductDetail.class);
        return util.exportExcel(list, "basProductDetail");
    }

    /**
     * 新增物品明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物品明细
     */
    @RequiresPermissions("bas:basProductDetail:add")
    @Log(title = "物品明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasProductDetail basProductDetail)
    {
        return toAjax(basProductDetailService.insertBasProductDetail(basProductDetail));
    }

    /**
     * 修改物品明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasProductDetail basProductDetail = basProductDetailService.selectBasProductDetailById(id);
        mmap.put("basProductDetail", basProductDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存物品明细
     */
    @RequiresPermissions("bas:basProductDetail:edit")
    @Log(title = "物品明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasProductDetail basProductDetail)
    {
        return toAjax(basProductDetailService.updateBasProductDetail(basProductDetail));
    }

    /**
     * 删除物品明细
     */
    @RequiresPermissions("bas:basProductDetail:remove")
    @Log(title = "物品明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basProductDetailService.deleteBasProductDetailByIds(ids));
    }
}
